import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path:"/",
    redirect:"/login",
    meta:{
      hidden:true
    }
  },
  {
    path:'/login',
    name:'Login',
    component:() => import('../views/login/login.vue')
  },
  {
    path:"/home",
    name:"Home",
    component:() => import('../views/home/index.vue'),
    children:[
      {
        path:"/firstPage",
        name:"firstPage",
        component:() => import('../views/asidePage/firstPage/index.vue')
      },
      {
        path:"/curriculum",
        name:"curriculum",
        component:() => import('../views/asidePage/curriculum/index.vue')
      },
      {
        path:'/orderD',
        name:'orderD',
        component:() => import('../views/asidePage/order/orderD/index.vue')
      },
      {
        path:'/orderT',
        name:'orderT',
        component:() => import('../views/asidePage/order/orderT/index.vue')
      },
      {
        path:"/rearnyua",
        name:"rearnyua",
        component:() => import('../views/asidePage/user/learnyua/index.vue')
      },
      {
        path:"/lecturer",
        name:"lecturer",
        component:() => import('../views/asidePage/user/lecturer/index.vue')
      },
      {
        path:"/lunbo",
        name:"lunbo",
        component:() => import('../views/asidePage/real/lunbo/index.vue'),
      },
      {
        path:"/article",
        name:"article",
        component:() => import('../views/asidePage/real/article/index.vue'),
      },
      {
        path:"/seckill",
        name:"seckill",
        component:() => import('../views/asidePage/Promotion/seckill/index.vue'),
      },
      {
        path:"/Discount",
        name:"Discount",
        component:() => import('../views/asidePage/Promotion/Discount/index.vue'),
      },
      {
        path:"/system",
        name:"system",
        component:() => import('../views/asidePage/system/index.vue'),
      },
    ]
  },
]
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

import Router from 'vue-router';
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}

// 登录拦截
const white = ['/login']
router.beforeEach((to,from,next) => {
  if(white.includes(to.path) || localStorage.getItem('token')){
    next()
  }else{
    next('/login')
  }
})

export default router
